@extends('layouts.app')

@section('title')
    维护模块
@endsection

@section('content')
    <div id="template">

        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">维护列表 <span style="float: right;">总共有 {{ $repairs->total() }} 条维护记录</span></div>

                <div class="panel-body">

                    <form class="form-inline" action="{{ url('admin/modules/repair') }}" method="get" style="margin-bottom: 20px;">
                        <select name="operatorId" class="form-control">
                            <option value="">全部维护人员</option>
                            @foreach($repairers as $repairer)
                                <option value="{{ $repairer->operator->id }}">{{ $repairer->operator->user->name }}</option>
                            @endforeach
                        </select>
                        <select name="status" class="form-control">
                            <option value="">全部状态</option>
                            @foreach($statuses as $key => $status)
                                <option value="{{ $key }}">{{ $status }}</option>
                            @endforeach
                        </select>
                        <button type="submit" class="btn btn-primary">筛选</button>
                        <button type="button" class="btn btn-danger" id="clear">清除条件</button>
                    </form>
                    @if($repairs->count() > 0)
                        <table class="table">
                            <thead>
                            <tr>
                                <th width="5%">id</th>
                                <td width="5%">报修者</td>
                                <td width="15%">报修者班级</td>
                                <td width="5%">平台</td>
                                <td width="25%">描述</td>
                                <td width="8%">维护人员</td>
                                <td width="5%">状态</td>
                                <td width="10%">预约时间段</td>
                                <td width="15%">创建时间</td>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($repairs as $repair)
                                <tr>
                                    <td>{{ $repair->id }}</td>
                                    <td>{{ $repair->user->name }}</td>
                                    <td>{{ $repair->user->class->name }}</td>
                                    <td>{{ $repair->platformText }}</td>
                                    <td>{{ $repair->description }}</td>
                                    <td>{{ $repair->operator ? $repair->operator->user->name : null }}</td>
                                    <td>
                                        @if($repair->status === 0)
                                            <button class="btn btn-danger btn-xs">{{ $repair->statusText }}</button>
                                        @elseif($repair->status === 1)
                                            <button class="btn btn-info btn-xs">{{ $repair->statusText }}</button>
                                        @elseif($repair->status === 2)
                                            <button class="btn btn-success btn-xs">{{ $repair->statusText }}</button>
                                        @elseif($repair->status === 3)
                                            <button class="btn btn-default btn-xs disabled">{{ $repair->statusText }}</button>
                                        @endif
                                    </td>
                                    <td>{{ $repair->schedule->content }}</td>
                                    <td>{{ $repair->created_at }}</td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                        <div style="text-align: center;">
                            {{ $repairs->appends(['operatorId' => $_GET['operatorId'] ?? null, 'status' => $_GET['status'] ?? null])->links() }}
                        </div>
                    @endif

                </div>
            </div>
        </div>

    </div>
@endsection

@section('js')
    <script>
        $("select[name='operatorId']").val('{{ $_GET['operatorId'] ?? null }}');
        $("select[name='status']").val('{{ $_GET['status'] ?? null }}');

        $("#clear").click(function(){
            clear();
        });

        function clear(){
            $("select[name='operatorId']").val(null);
            $("select[name='status']").val(null);
        }
    </script>
@endsection